#include "ioc.h"

struct gpiod_chip *chip;
struct gpiod_line *line;

int key_read(unsigned int key)
{

    chip = gpiod_chip_open_by_label("GPIOF");
    if (!chip)
    {
        printf("Failed to open GPIO chip\n");
        return 1;
    }
    line = gpiod_chip_get_line(chip, key);
    if (!line)
    {
        printf("Failed to get line\n");
        return 1;
    }
    if (gpiod_line_request_input(line, "") != 0)
    {
        gpiod_line_release(line);
        printf("Failed to request input\n");
        return 1;
    }
    int value = gpiod_line_get_value(line);
    printf("value: %s\n", value ? "not_pressed" : "pressed");
    gpiod_line_release(line);
    gpiod_chip_close(chip);
    return value;
}